package com.yzt.conf;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import com.jagregory.shiro.freemarker.ShiroTags;

import freemarker.template.TemplateException;

@Component
public class FreeMarkerConfig {
	
	@Autowired
	private FreeMarkerProperties freeMarkerProperties;

	@Bean
	public FreeMarkerConfigurer freeMarkerConfigurer() throws IOException, TemplateException {
		FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
		freeMarkerConfigurer.setTemplateLoaderPaths(freeMarkerProperties.getTemplateLoaderPath());
		freemarker.template.Configuration configuration = freeMarkerConfigurer.createConfiguration();
		configuration.setDefaultEncoding("UTF-8");
		configuration.setSharedVariable("shiro", new ShiroTags());
		freeMarkerConfigurer.setConfiguration(configuration);
		return freeMarkerConfigurer;
	}
}
